import { UploadOutlined } from '@ant-design/icons';
import style from './index.less';
import {
  Button,
  Upload,
  Space,
  Input,
  Select,
  DatePicker,
  Radio,
  Form,
} from 'antd';
import { Descriptions } from 'antd';
import { Tabs } from 'antd';
import request from '@/http';
import React, { useState, useEffect } from 'react';
import Submit from '../TaskManagement/Submit';
const { Option } = Select;
const { TabPane } = Tabs;
const { TextArea } = Input;
import { history } from '@/.umi/core/history';
import moment from 'moment';
import { format } from 'prettier';
const layout = {
  labelCol: { span: 2 },
  wrapperCol: { span: 16 },
};

const props = {
  action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
  onChange({ file, fileList }) {
    if (file.status !== 'uploading') {
      console.log(file, fileList);
    }
  },
  defaultFileList: [
    {
      uid: '1',
      name: 'xxx.png',
      status: 'done',
      response: 'Server Error 500',
      url: 'http://www.baidu.com/xxx.png',
    },
    {
      uid: '2',
      name: 'yyy.png',
      status: 'done',
      url: 'http://www.baidu.com/yyy.png',
    },
  ],
};

const columns = [
  {
    title: '姓名',
    dataIndex: 'studentName',
    key: 'studentName',
  },
  {
    title: '学号',
    dataIndex: 'studentNo',
    key: 'studentNo',
  },
  {
    title: '专业',
    dataIndex: 'majorName',
    key: 'majorName',
  },
  {
    title: '学院',
    dataIndex: 'collegeName',
    key: 'collegeName',
  },
  {
    title: '年级',
    dataIndex: 'gradeName',
    key: 'gradeName',
  },
  {
    title: '班级',
    dataIndex: 'className',
    key: 'className',
  },
  {
    title: '班主任',
    dataIndex: 'teacherName',
    key: 'teacherName',
  },
];
const LeaveDetailsts = (porps: any) => {
  const [formObject] = Form.useForm();
  const [user, setUser] = useState<any>({
    key: '1',
    studentName: '裴章燕',
    studentNo: '189000531',
    majorName: '软件工程',
    collegeName: '软件学院',
    gradeName: '18级',
    className: '1890005',
    teacherName: '李竹君',
  });
  const [leave, setLeave] = useState<any>({
    className: '1',
    collegeName: '1',
    id: 1,
    majorName: '1',
    studentName: '1',
    studentNo: 1,
    teacherName: '1',
    teamName: '1',
    vacationBeginDate: null,
    vacationEndDate: null,
    vacationExplain: '1',
    vacationReason: '1',
    vacationStatus: '1',
    vacationSubmitDate: '1',
    vacationTheme: '1',
    attachment: null,
  });
  /**
   * 获取用户基本信息
   */
  const loadData = async () => {
    const result1: any = await request.post('/ask_for_leave/a_t_s/ask/all12', {
      id: porps.location.state.id,
    });
    const result: any = await request.post(
      '/information/student/selectPersonalInfo',
    );
    if (result.success) {
      setUser(result.data);
    }
    if (result1.success) {
      setLeave(result1.data);
      formObject.setFieldsValue({
        vacationTheme: result1?.data?.vacationTheme,
        vacationBeginDate: moment(result1?.data?.vacationBeginDate),
        // vacationBeginDate:result1?.data?.vacationBeginDate.format('YYYY-MM-DD HH:mm:ss'),
        className: result1?.data?.className,
        collegeName: result1?.data?.collegeName,
        id: result1?.data?.id,
        majorName: result1?.data?.majorName,
        studentName: result1?.data?.studentName,
        studentNo: result1?.data?.studentNo,
        teacherName: result1?.data?.teacherName,
        teamName: result1?.data?.teamName,
        vacationEndDate: moment(result1?.data?.vacationEndDate),
        // vacationEndDate:result1?.data?.vacationEndDate.format('YYYY-MM-DD HH:mm:ss'),
        vacationExplain: result1?.data?.vacationExplain,
        vacationReason: result1?.data?.vacationReason,
        vacationStatus: result1?.data?.vacationStatus,
        vacationSubmitDate: result1?.data?.vacationSubmitDate,
        attachment: result1?.data?.attachment,
      });
    }
    console.log(result1.data);
  };

  useEffect(() => {
    loadData();
  }, []);
  return (
    <div>
      <Descriptions title="个人信息">
        <Descriptions.Item label="姓名">{leave.studentName}</Descriptions.Item>
        <Descriptions.Item label="学号">{leave.studentNo}</Descriptions.Item>
        <Descriptions.Item label="专业">{leave.majorName}</Descriptions.Item>
        <Descriptions.Item label="院系">{leave.collegeName}</Descriptions.Item>
        <Descriptions.Item label="年级">{user.gradeName}</Descriptions.Item>
        <Descriptions.Item label="班级">{leave.className}</Descriptions.Item>
        <Descriptions.Item label="班主任">
          {leave.teacherName}
        </Descriptions.Item>
      </Descriptions>
      <div>
        <Form
          {...layout}
          name="LeaveForm"
          form={formObject}
          initialValues={leave}
          preserve={false}
        >
          <Form.Item
            name="vacationTheme"
            rules={[
              { required: true, whitespace: true, message: '主题不能为空!' },
            ]}
            label="主题"
            style={{ marginLeft: '-3rem' }}
          >
            <Input disabled placeholder="请输入请假具体原因"></Input>
          </Form.Item>

          <Form.Item
            name="vacationBeginDate"
            rules={[
              {
                required: true,
                whitespace: true,
                message: '请选择请假开始日期!',
              },
            ]}
            label="请假开始日期"
          >
            <DatePicker disabled format="YYYY-MM-DD HH:mm:ss" />
          </Form.Item>

          <Form.Item
            name="vacationEndDate"
            rules={[
              {
                required: true,
                whitespace: true,
                message: '请选择请假结束日期!',
              },
            ]}
            label="请假结束日期"
          >
            <DatePicker format="YYYY-MM-DD HH:mm:ss" disabled />
          </Form.Item>
          <Form.Item
            name="vacationReason"
            rules={[
              { required: true, whitespace: true, message: '请选择请假原因!' },
            ]}
            label="请假原因"
          >
            <Radio.Group disabled>
              <Radio value="病假">病假（需附校医院证明）</Radio>
              <Radio value="事假">事假</Radio>
              <Radio value="其他">其他</Radio>
            </Radio.Group>
          </Form.Item>

          <Form.Item
            name="vacationExplain"
            rules={[
              {
                required: true,
                whitespace: true,
                message: '请输入请假具体原因!',
              },
            ]}
          >
            <TextArea
              rows={3}
              placeholder="请输入请假具体原因"
              disabled
            ></TextArea>
          </Form.Item>

          <Form.Item name="attachment" label="相关附件：">
            <a>{leave.attachment}</a>
          </Form.Item>

          <Form.Item
            name="teacherName"
            rules={[
              { required: true, whitespace: true, message: '审批人不能为空!' },
            ]}
            label="审批人"
          >
            <Input placeholder="请输入审批人" disabled />
          </Form.Item>
        </Form>
        <Button
          type="link"
          onClick={() => {
            history.push(`/Student/LeaveManagement/index`);
          }}
        >
          返回
        </Button>
      </div>
    </div>
  );
};
export default LeaveDetailsts;
